package com.heiyu.controller.response;

import com.heiyu.constants.CodeMsgEnum;
import com.heiyu.constants.ResponseMsgEnum;
import com.heiyu.utils.CodeEnum;

import java.io.Serializable;

public class BaseResponse  implements Serializable {

    private String code;

    private String msg;

    private Object data;

    public  void success(){
        setCode(CodeEnum.SUCCESS);
        setMsg(CodeMsgEnum.SUCCESS);
    }


    public void systemError(){
        setCode(CodeEnum.SYSTEM_ERROR);
        setMsg(CodeMsgEnum.SYSTEM_ERROR);
    }

    public void businessError(){
        setCode(CodeEnum.BUSSINESS_ERROR);
        setMsg(CodeMsgEnum.BUSSINESS_ERROR);
    }

    public void error(String msg){
        if(msg.equals(ResponseMsgEnum.USER_NOT_LOGIN)){
            setCode(CodeEnum.LOGIN_LOST);
            setMsg(msg);
        }else{
            setCode(CodeEnum.BUSSINESS_ERROR);
            setMsg(msg);
        }
    }

    public void error(String code,String msg){
        setCode(code);
        setMsg(msg);
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
